<?xml version="1.0" encoding="UTF-8"?>
<!-- Júnior Moura
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:t="http://myfaces.apache.org/tomahawk" 
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:decorate template="/tema/padrao.xhtml">
        <ui:define name="centro" >
            <t:saveState value="#{servicoBean.servico}" />
            <t:saveState value="#{servicoBean.servicos}" />
            <h:form id="form" >                
                <p:panel header="Gestão de Serviços" >
                    <p:commandButton id="btnBuscar" value="Consultar" actionListener="#{servicoBean.consultar}" process="@form" update="tabela" />
                    <p:commandButton id="btnNovo" value="Novo" action="#{servicoBean.novo}" ajax="false"/>
                    <p:dataTable id="tabela" 
                                 value="#{servicoBean.servicos}"
                                 var="s"
                                 paginator="true"
                                 emptyMessage="Sem resultados." >
                        <p:column headerText="Nome do Serviço" sortBy="#{s.nome}" filterBy="#{s.nome}" id="nome">
                            <h:outputText value="#{s.nome}" />
                        </p:column>
                        <p:column headerText="Valor do Serviço" >
                            <h:outputText value="#{s.valor}" />
                        </p:column>
                        <p:column headerText="Status" >
                            <h:outputText value="#{s.ativo ? 'Sim' : 'Não'}" />
                        </p:column>
                        <p:column headerText="Editar" >
                            <p:commandButton value="Editar" action="#{servicoBean.editar}" ajax="false">
                                <f:setPropertyActionListener value="#{s}" target="#{servicoBean.servico}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Excluir" >
                            <p:commandButton value="Excluir" oncomplete="confirm.show()" >
                                <f:setPropertyActionListener value="#{s}" target="#{servicoBean.servico}" />
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>

            <h:form id="formConfirm" >
                <p:confirmDialog modal="true" draggable="false" appendToBody="true" closable="true" message="Deseja realmente excluir este serviço?" header="Aviso" widgetVar="confirm" >
                    <p:commandButton value="Sim" oncomplete="confirm.hide()" actionListener="#{servicoBean.excluir}" update=":form:tabela" />
                    <p:commandButton value="Não" oncomplete="confirm.hide()" />
                </p:confirmDialog>
            </h:form>
        </ui:define>
    </ui:decorate>
</html>



